package com.lfd.rabbitmq.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.rabbitmq.service
 * @文件名: DirectMessageProducer
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/10/11 21:19
 * @描述：
 */
@Slf4j
@Service
public class DirectMessageProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 发送消息到正常业务队列
    public void sendMessage(String message) {
        CorrelationData correlationData = new CorrelationData("unique_id_" + System.currentTimeMillis());
        rabbitTemplate.convertAndSend("business_exchange", "business_routing_key", message, correlationData);
//        rabbitTemplate.convertAndSend("business_exchange", "business_routing_key", message, correlationData);

        log.info("DirectMessageProducer Message sent to business queue: {}", message);

    }
}
